#property indicator_separate_window
#property indicator_buffers 8

extern double koef_1440 = 1.0;//1;
extern double koef_240 = 1.0;//0.5;
extern double koef_60 = 1.0;//0.25;
extern double koef_30 = 1.0;//0.15;
extern double koef_15 = 1.0;//0.1;
extern double koef_5 = 1.0;//0.05;
extern double koef_1 = 1.0;//0.025;

//---- buffers
double BufferEUR[];
double BufferGBP[];
double BufferUSD[];
double BufferCAD[];
double BufferAUD[];
double BufferNZD[];
double BufferCHF[];
double BufferJPY[];

double EURUSD;
double EURGBP;
double EURCAD;
double EURCHF;
double EURJPY;
double EURAUD;
double EURNZD;
double GBPUSD;
double GBPCAD;
double GBPCHF;
double GBPJPY;
double GBPAUD;
double GBPNZD;
double USDCAD;
double USDCHF;
double USDJPY;
double AUDUSD;
double NZDUSD;
double CADCHF;
double CADJPY;
double AUDCAD;
double NZDCAD;
double AUDCHF;
double AUDJPY;
double AUDNZD;
double NZDCHF;
double NZDJPY;
double CHFJPY;

datetime timestart = 0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
   timestart = TimeLocal();
   
   SetIndexStyle(0,DRAW_LINE );
   SetIndexBuffer(0,BufferEUR);
   SetIndexLabel(0,"EUR");

   SetIndexStyle(1,DRAW_LINE );
   SetIndexBuffer(1,BufferGBP);
   SetIndexLabel(1,"GBP");

   SetIndexStyle(2,DRAW_LINE );
   SetIndexBuffer(2,BufferUSD);
   SetIndexLabel(2,"USD");

   SetIndexStyle(3,DRAW_LINE );
   SetIndexBuffer(3,BufferCAD);
   SetIndexLabel(3,"CAD");

   SetIndexStyle(4,DRAW_LINE );
   SetIndexBuffer(4,BufferAUD);
   SetIndexLabel(4,"AUD");

   SetIndexStyle(5,DRAW_LINE );
   SetIndexBuffer(5,BufferNZD);
   SetIndexLabel(5,"NZD");

   SetIndexStyle(6,DRAW_LINE );
   SetIndexBuffer(6,BufferCHF);
   SetIndexLabel(6,"CHF");

   SetIndexStyle(7,DRAW_LINE );
   SetIndexBuffer(7,BufferJPY);  
   SetIndexLabel(7,"JPY"); 
   
//----
   return(0);
}

//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
	return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{   
   int limit;

   int    counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   
   if (limit > 2) limit = 2;

	for(int i=0;i<limit;i++)
	{
		LoadData(Period(),i);
		BufferEUR[i]=GetStrength_EUR();
		BufferGBP[i]=GetStrength_GBP();
		BufferUSD[i]=GetStrength_USD();
		BufferCAD[i]=GetStrength_CAD();
		BufferAUD[i]=GetStrength_AUD();
		BufferNZD[i]=GetStrength_NZD();
		BufferCHF[i]=GetStrength_CHF();
		BufferJPY[i]=GetStrength_JPY();     

		if( i==limit-1 && TimeLocal()-timestart>10)
		{
   		timestart = TimeLocal();

			LoadData(1440,0);

			LoadData(240,0);

			LoadData(60,0);

			LoadData(30,0);

			LoadData(15,0);

			LoadData(5,0);

			LoadData(1,0);
		}
	}
//----
   return(0);
}

double GetRib(string symbol, int tf, int offset){
   //double MA1 = iMA(symbol,tf,5,0,MODE_SMA,PRICE_MEDIAN,offset);
   //double MA2 = iMA(symbol,tf,35,0,MODE_SMA,PRICE_MEDIAN,offset);

   int red_cnt = 0;
   int green_cnt = 0;

   double g_ima_188 = iMA(symbol, tf, 5, 0, MODE_EMA, PRICE_CLOSE, offset);
   double g_ima_196 = iMA(symbol, tf, 5, 0, MODE_EMA, PRICE_CLOSE, offset + 1);
   if (g_ima_188==0 || g_ima_196==0) return(100);
   if (g_ima_188 < g_ima_196) red_cnt++;
   else green_cnt++;
   g_ima_188 = iMA(symbol, tf, 10, 0, MODE_EMA, PRICE_CLOSE, offset);
   g_ima_196 = iMA(symbol, tf, 10, 0, MODE_EMA, PRICE_CLOSE, offset + 1);
   if (g_ima_188==0 || g_ima_196==0) return(100);
   if (g_ima_188 < g_ima_196) red_cnt++;
   else green_cnt++;
   g_ima_188 = iMA(symbol, tf, 20, 0, MODE_EMA, PRICE_CLOSE, offset);
   g_ima_196 = iMA(symbol, tf, 20, 0, MODE_EMA, PRICE_CLOSE, offset + 1);
   if (g_ima_188==0 || g_ima_196==0) return(100);
   if (g_ima_188 < g_ima_196) red_cnt++;
   else green_cnt++;
   g_ima_188 = iMA(symbol, tf, 30, 0, MODE_EMA, PRICE_CLOSE, offset);
   g_ima_196 = iMA(symbol, tf, 30, 0, MODE_EMA, PRICE_CLOSE, offset + 1);
   if (g_ima_188==0 || g_ima_196==0) return(100);
   if (g_ima_188 < g_ima_196) red_cnt++;
   else green_cnt++;
   
   
   if (red_cnt==4) return(-1);
   if (red_cnt==3) return(-0.5);
   if (green_cnt==4) return(1);
   if (green_cnt==3) return(0.5);
   return(0);
}

void LoadData(int tf, int offset)
{
	double v1;

	EURUSD = GetRib("EURUSD",tf,offset);
	EURGBP = GetRib("EURGBP",tf,offset);
	EURCAD = GetRib("EURCAD",tf,offset);
	EURCHF = GetRib("EURCHF",tf,offset);
	EURJPY = GetRib("EURJPY",tf,offset);
	EURAUD = GetRib("EURAUD",tf,offset);
	EURNZD = GetRib("EURNZD",tf,offset);
	GBPUSD = GetRib("GBPUSD",tf,offset);
	GBPCAD = GetRib("GBPCAD",tf,offset);
	GBPCHF = GetRib("GBPCHF",tf,offset);
	GBPJPY = GetRib("GBPJPY",tf,offset);
	GBPAUD = GetRib("GBPAUD",tf,offset);
	GBPNZD = GetRib("GBPNZD",tf,offset);
	USDCAD = GetRib("USDCAD",tf,offset);
	USDCHF = GetRib("USDCHF",tf,offset);
	USDJPY = GetRib("USDJPY",tf,offset);
	AUDUSD = GetRib("AUDUSD",tf,offset);
	NZDUSD = GetRib("NZDUSD",tf,offset);
	CADCHF = GetRib("CADCHF",tf,offset);
	CADJPY = GetRib("CADJPY",tf,offset);
	AUDCAD = GetRib("AUDCAD",tf,offset);
	NZDCAD = GetRib("NZDCAD",tf,offset);
	AUDCHF = GetRib("AUDCHF",tf,offset);
	AUDJPY = GetRib("AUDJPY",tf,offset);
	AUDNZD = GetRib("AUDNZD",tf,offset);
	NZDCHF = GetRib("NZDCHF",tf,offset);
	NZDJPY = GetRib("NZDJPY",tf,offset);
	CHFJPY = GetRib("CHFJPY",tf,offset);
}

double GetStrength_EUR(){
   double result = 0;
   double v1;

   v1 = EURUSD;   if (v1>10) return(0);   result+=v1;
   v1 = EURGBP;   if (v1>10) return(0);   result+=v1;
   v1 = EURCAD;   if (v1>10) return(0);   result+=v1;
   v1 = EURCHF;   if (v1>10) return(0);   result+=v1;
   v1 = EURAUD;   if (v1>10) return(0);   result+=v1;
   v1 = EURNZD;   if (v1>10) return(0);   result+=v1;
   v1 = EURJPY;   if (v1>10) return(0);   result+=v1;
   
   return(result);
}

double GetStrength_GBP(){
   double result = 0;
   double v1;

   v1 = GBPUSD;   if (v1>10) return(0);   result+=v1;
   v1 = EURGBP;   if (v1>10) return(0);   result-=v1;
   v1 = GBPCAD;   if (v1>10) return(0);   result+=v1;
   v1 = GBPCHF;   if (v1>10) return(0);   result+=v1;
   v1 = GBPAUD;   if (v1>10) return(0);   result+=v1;
   v1 = GBPNZD;   if (v1>10) return(0);   result+=v1;
   v1 = GBPJPY;   if (v1>10) return(0);   result+=v1;
   
   return(result);
}

double GetStrength_USD(){
   double result = 0;
   double v1;

   v1 = EURUSD;   if (v1>10) return(0);   result-=v1;
   v1 = GBPUSD;   if (v1>10) return(0);   result-=v1;
   v1 = USDCAD;   if (v1>10) return(0);   result+=v1;
   v1 = USDCHF;   if (v1>10) return(0);   result+=v1;
   v1 = AUDUSD;   if (v1>10) return(0);   result-=v1;
   v1 = NZDUSD;   if (v1>10) return(0);   result-=v1;
   v1 = USDJPY;   if (v1>10) return(0);   result+=v1;
   
   return(result);
}

double GetStrength_CAD(){
   double result = 0;
   double v1;

   v1 = EURCAD;   if (v1>10) return(0);   result-=v1;
   v1 = GBPCAD;   if (v1>10) return(0);   result-=v1;
   v1 = USDCAD;   if (v1>10) return(0);   result-=v1;
   v1 = CADCHF;   if (v1>10) return(0);   result+=v1;
   v1 = AUDCAD;   if (v1>10) return(0);   result-=v1;
   v1 = NZDCAD;   if (v1>10) return(0);   result-=v1;
   v1 = CADJPY;   if (v1>10) return(0);   result+=v1;
   
   return(result);
}

double GetStrength_AUD(){
   double result = 0;
   double v1;

   v1 = AUDUSD;   if (v1>10) return(0);   result+=v1;
   v1 = GBPAUD;   if (v1>10) return(0);   result-=v1;
   v1 = AUDCAD;   if (v1>10) return(0);   result+=v1;
   v1 = AUDCHF;   if (v1>10) return(0);   result+=v1;
   v1 = EURAUD;   if (v1>10) return(0);   result-=v1;
   v1 = AUDNZD;   if (v1>10) return(0);   result+=v1;
   v1 = AUDJPY;   if (v1>10) return(0);   result+=v1;
   
   return(result);
}

double GetStrength_NZD(){
   double result = 0;
   double v1;

   v1 = NZDUSD;   if (v1>10) return(0);   result+=v1;
   v1 = GBPNZD;   if (v1>10) return(0);   result-=v1;
   v1 = NZDCAD;   if (v1>10) return(0);   result+=v1;
   v1 = NZDCHF;   if (v1>10) return(0);   result+=v1;
   v1 = EURNZD;   if (v1>10) return(0);   result-=v1;
   v1 = AUDNZD;   if (v1>10) return(0);   result-=v1;
   v1 = NZDJPY;   if (v1>10) return(0);   result+=v1;
   
   return(result);
}

double GetStrength_CHF(){
   double result = 0;
   double v1;

   v1 = USDCHF;   if (v1>10) return(0);   result-=v1;
   v1 = GBPCHF;   if (v1>10) return(0);   result-=v1;
   v1 = NZDCHF;   if (v1>10) return(0);   result-=v1;
   v1 = CADCHF;   if (v1>10) return(0);   result-=v1;
   v1 = EURCHF;   if (v1>10) return(0);   result-=v1;
   v1 = AUDCHF;   if (v1>10) return(0);   result-=v1;
   v1 = CHFJPY;   if (v1>10) return(0);   result+=v1;
   
   return(result);
}

double GetStrength_JPY(){
   double result = 0;
   double v1;

   v1 = USDJPY;   if (v1>10) return(0);   result-=v1;
   v1 = GBPJPY;   if (v1>10) return(0);   result-=v1;
   v1 = NZDJPY;   if (v1>10) return(0);   result-=v1;
   v1 = CADJPY;   if (v1>10) return(0);   result-=v1;
   v1 = EURJPY;   if (v1>10) return(0);   result-=v1;
   v1 = AUDJPY;   if (v1>10) return(0);   result-=v1;
   v1 = CHFJPY;   if (v1>10) return(0);   result-=v1;
   
   return(result);
}

